<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.situ.meetingRoom.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 闫佳宁
  Date: 2024/1/22
  Time: 9:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<html>
<head>
    <base href="<%=baseUrl%>">
    <title>会议室预约系统</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<style>
    .demo-login-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }

    body {
        background-image: url("img/img.png");
        background-repeat: no-repeat;
        background-position: center;
        background-size: cover;
        background-attachment: fixed;
    }

    form {
        width: 600px;
        height: 400px;
        margin: 10% auto;
        background-color: #FFF5;
        border-radius: 15px;
        box-shadow: 10px 10px 10px;
    }

    h1 {
        text-align: center;
        padding: 10px;
    }

    .error {
        text-align: center;
        color: red;
    }

    .verCode {
        cursor: pointer;
    }
    .online{
        border: 1px solid black;
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>
<body>
<%
    String sId = null;
    String password = null;
    String remember = null;
    //读取Cookie
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        Map<String, String> cookieMap = new HashMap<>();
        for (Cookie c : cookies) {
            cookieMap.put(c.getName(), c.getValue());
        }
        sId = cookieMap.get("sId");
        password = cookieMap.get("password");
        remember = cookieMap.get("remember");
    }
    if ("true".equals(remember)){
        sId = null;
        password = null;
    }
%>
<form class="layui-form" action="user?action=login" method="post">
    <h1>员工登录</h1>
    <div class="online">当前在线${applicationScope.onlineCount}人</div>
    <div class="error">${error}</div>
    <div class="demo-login-container">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input type="text" name="id" value="<%=sId != null ? sId : ""%>" lay-verify="required" placeholder="用户名"
                       lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="password" value="<%=password != null ? password : ""%>" lay-verify="required" placeholder="密   码"
                       lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-xs7">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-vercode"></i>
                        </div>
                        <input type="text" name="verCode" value="" lay-verify="required" placeholder="验证码"
                               lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
                <div class="layui-col-xs5">
                    <div style="margin-left: 10px;">
                        <img src="verCode" class="verCode" title="点击刷新">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <input type="checkbox" name="remember" lay-skin="primary" value="true" <%="true".equals(remember)? "checked" : ""%> title="记住密码">
            <a href="#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>
        </div>
    </div>
</form>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->

<script src="layui/layui.js"></script>
<script>
    // 防止套娃
    (function (window) {
        if (window.location !== top.location) {
            window.top.location = window.location;
        }
    })(this);

    //最原始的js操作
    document.getElementsByClassName("verCode")[0].onclick = function () {
        this.setAttribute("src", "verCode?" + new Date().getTime());
    }
</script>
</body>
</html>
